// pages/goodsLink/goodsLink.js
var sliderWidth = 16; // 需要设置slider的宽度，用于计算中间位置
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: ["购物车", "商品列表", "分享记录", "收藏夹"],
    sum: 0, //购物车已选
    sum_S: 0, //商品列表已选
    limt: false,//购物车已选5个
    limt_S: false,//商品列表已选5个
    activeIndex: 0,
    sliderOffset: 0,
    popup:false,//商品分类的显隐
    sliderLeft: 0,
    midShouVal:'0',//二级分类标识
    maxShouVal:'0',//一级分类标识
    imgUrl: getApp().globalData.imgUrl,
    maxClassify: [{//商品分类集合
      maxID:'x01',
      max: '裙子',
      midClassify: [{
        midID: 'd01',
        mid: '春夏装',
        minClassify: [{ min: '连衣裙' }, { min: '黑色裙', }, { min: '白色裙', }]
      }, {
          midID: 'd02',
        mid: '秋冬装',
        minClassify: [{min: '吊带裙',}]
      }]
    }, {
      maxID: 'x02',
      max: '裤子',
      midClassify: [{
        midID: 'd03',
        mid: '春夏装'
      }, {
          midID: 'd04',
        mid: '秋冬装'
      }]
    }, {
        maxID: 'x03',
      max: '运动系列'
    }, {
        maxID: 'x04',
      max: '护肤品'
    }, {
        maxID: 'x05',
      max: '上衣'
    }, {
        maxID: 'x06',
      max: '婴幼产品'
    }, ],
    carlist: [{
        goodsId: '100',
        goodsmoney: '328.00',
        goodsImg: 'proimg.jpg',
        goodsName: '2017秋季新品时尚金属针扣粗跟方头单鞋',
        checked: false
      },
      {
        goodsId: '200',
        goodsmoney: '328.00',
        goodsImg: 'proimg.jpg',
        goodsName: '2017秋季新品时尚金属针扣粗跟方头单鞋',
        checked: false
      },
      {
        goodsId: '300',
        goodsmoney: '328.00',
        goodsImg: 'proimg.jpg',
        goodsName: '2017秋季新品时尚金属针扣粗跟方头单鞋',
        checked: false
      },
      {
        goodsId: '400',
        goodsmoney: '328.00',
        goodsImg: 'proimg.jpg',
        goodsName: '2017秋季新品时尚金属针扣粗跟方头单鞋',
        checked: false
      },
      {
        goodsId: '500',
        goodsmoney: '328.00',
        goodsImg: 'proimg.jpg',
        goodsName: '2017秋季新品时尚金属针扣粗跟方头单鞋',
        checked: false
      },
      {
        goodsId: '600',
        goodsmoney: '328.00',
        goodsImg: 'proimg.jpg',
        goodsName: '2017秋季新品时尚金属针扣粗跟方头单鞋',
        checked: false
      },
    ],
    goodslist: [{
      goodsId: '100',
      goodsmoney: '328.00',
      goodsImg: 'proimg.jpg',
      goodsName: '2018秋季新品时尚全球限量发售',
      checked: false
    },
    {
      goodsId: '200',
      goodsmoney: '328.00',
      goodsImg: 'proimg.jpg',
      goodsName: '2018秋季新品时尚全球限量发售',
      checked: false
    },
    {
      goodsId: '300',
      goodsmoney: '328.00',
      goodsImg: 'proimg.jpg',
      goodsName: '2018秋季新品时尚全球限量发售',
      checked: false
    },
    {
      goodsId: '400',
      goodsmoney: '328.00',
      goodsImg: 'proimg.jpg',
      goodsName: '2018秋季新品时尚全球限量发售',
      checked: false
    },
    {
      goodsId: '500',
      goodsmoney: '328.00',
      goodsImg: 'proimg.jpg',
      goodsName: '2018秋季新品时尚全球限量发售',
      checked: false
    },
    {
      goodsId: '600',
      goodsmoney: '328.00',
      goodsImg: 'proimg.jpg',
      goodsName: '2017秋季新品时尚金属针扣粗跟方头单鞋',
      checked: false
    },
    ]
  },
  tabClick: function(e) {
    this.setData({
      sliderOffset: e.currentTarget.offsetLeft,
      activeIndex: e.currentTarget.id
    });
  },
  // 购物车单个商品选择
  selectCbox: function (e) {
    var gid = e.currentTarget.dataset.gid
    var items = this.data.carlist;
    if (e.currentTarget.dataset.disabled) { return }
    console.log(gid);
    for (var i = 0; i < items.length; i++) {
      if (gid == items[i].goodsId) {
        items[i].checked = !items[i].checked;
      }
    }
    this.setData({
      carlist: items
    });
  },
  // 购车商品选择监听
  checkboxChange: function (e) {
    var selectedArr = e.detail.value;
    var len = selectedArr.length;
    if (len >= 5) {
      this.setData({
        sum: e.detail.value.length,
        limt: true
      })
      console.log('ok, 其它可以灰掉');
    } else {
      this.setData({
        sum: e.detail.value.length,
        limt: false
      })
    }
  },
  // 商品列表单个商品选择
  selectCbox_S: function (e) {
    var gid = e.currentTarget.dataset.gid
    var items = this.data.goodslist;
    if (e.currentTarget.dataset.disabled) { return }
    console.log(gid);
    for (var i = 0; i < items.length; i++) {
      if (gid == items[i].goodsId) {
        items[i].checked = !items[i].checked;
      }
    }
    this.setData({
      goodslist: items
    });
  },
  // 商品列表商品选择监听
  checkboxChange_S: function (e) {
    var selectedArr = e.detail.value;
    var len = selectedArr.length;
    if (len >= 5) {
      this.setData({
        sum_S: e.detail.value.length,
        limt_S: true
      })
      console.log('ok, 其它可以灰掉');
    } else {
      this.setData({
        sum_S: e.detail.value.length,
        limt_S: false
      })
    }
  },
  // 商品二级分类的点击
  minshow: function(e) {
    if (e.currentTarget.id == this.data.midShouVal){//判断是否对同一二级分类点击两次
      this.setData({
        midShouVal: '0'
      })
    }else{
      this.setData({
        midShouVal: e.currentTarget.id
      })
    }
  },
  // 商品一级分类的点击
  midshow: function (e) {
    if (e.currentTarget.id == this.data.maxShouVal) {//判断是否对同一一级分类点击两次
      this.setData({
        maxShouVal: '0'
      })
    } else {
      this.setData({
        maxShouVal: e.currentTarget.id
      })
    }
  },
  // 商品分类的显隐
  payOnlineType:function(){
  this.setData({
    popup: !this.data.popup
  })
  },
  //三级分类跳转
  stoptap:function(){
  //跳转操作 
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    wx.setNavigationBarTitle({
      title: '阿迪达斯官方旗舰店'
    })
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
          sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
        });
      }
    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})